package com.hanthink.web.controller.manhour;

import java.util.List;
import java.util.Map;

import com.hanthink.common.core.domain.model.LoginUser;
import com.hanthink.common.utils.ServletUtils;
import com.hanthink.framework.web.service.TokenService;
import com.hanthink.system.domain.manhour.ImportEntity.PLineMachineStructureImportEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.system.domain.manhour.PLineMachineStructure;
import com.hanthink.system.service.manhour.IPLineMachineStructureService;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 产线的设备维护Controller
 * 
 * @author hanthink
 * @date 2022-05-05
 */
@RestController
@RequestMapping("/manhour/PLineMachineStructure")
public class PLineMachineStructureController extends BaseController
{
    @Autowired
    private IPLineMachineStructureService pLineMachineStructureService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询产线的设备维护列表
     */
    @PreAuthorize("@ss.hasPermi('manhour:PLineMachineStructure:list')")
    @GetMapping("/list")
    public TableDataInfo list(PLineMachineStructure pLineMachineStructure)
    {
        startPage();
        List<PLineMachineStructure> list = pLineMachineStructureService.selectPLineMachineStructureList(pLineMachineStructure);
        return getDataTable(list);
    }

    /**
     * 导出产线的设备维护列表
     */
    @PreAuthorize("@ss.hasPermi('manhour:PLineMachineStructure:export')")
    @Log(title = "产线的设备维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PLineMachineStructure pLineMachineStructure)
    {
        List<PLineMachineStructure> list = pLineMachineStructureService.selectPLineMachineStructureList(pLineMachineStructure);
        ExcelUtil<PLineMachineStructure> util = new ExcelUtil<PLineMachineStructure>(PLineMachineStructure.class);
        return util.exportExcel(list, "PLineMachineStructure");
    }

    /**
     * 获取产线的设备维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('manhour:PLineMachineStructure:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pLineMachineStructureService.selectPLineMachineStructureById(id));
    }

    /**
     * 新增产线的设备维护
     */
    @PreAuthorize("@ss.hasPermi('manhour:PLineMachineStructure:add')")
    @Log(title = "产线的设备维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PLineMachineStructure pLineMachineStructure)
    {
        return toAjax(pLineMachineStructureService.insertPLineMachineStructure(pLineMachineStructure));
    }

    /**
     * 修改产线的设备维护
     */
    @PreAuthorize("@ss.hasPermi('manhour:PLineMachineStructure:edit')")
    @Log(title = "产线的设备维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PLineMachineStructure pLineMachineStructure)
    {
        return toAjax(pLineMachineStructureService.updatePLineMachineStructure(pLineMachineStructure));
    }

    /**
     * 删除产线的设备维护
     */
    @PreAuthorize("@ss.hasPermi('manhour:PLineMachineStructure:remove')")
    @Log(title = "产线的设备维护", businessType = BusinessType.DELETE)
	@DeleteMapping
    public AjaxResult remove(@RequestBody List<PLineMachineStructure> list)
    {
        for (PLineMachineStructure p :
                list) {
            p.toString();
        }
        return toAjax(pLineMachineStructureService.deletePLineMachineStructureByIds(list));
    }


    /**
     * @Description: 生产设备维护模板下载
     * @param
     * @return: com.hanthink.common.core.domain.AjaxResult
     * @Author: 唐子越
     * @Date: 2023/7/6
     */
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate(){
        ExcelUtil<PLineMachineStructureImportEntity> util =
                new ExcelUtil<PLineMachineStructureImportEntity>(PLineMachineStructureImportEntity.class);
        return util.importTemplateExcel("产线设备维护");
    }


    /**
     * @Description: 数据导入接口
     * @param file
     * @return: com.hanthink.common.core.domain.AjaxResult
     * @Author: 唐子越
     * @Date: 2023/7/6 15:09
     */
    @Log(title = "产线的设备维护", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('manhour:PLineMachineStructure:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<PLineMachineStructureImportEntity> util =
                new ExcelUtil<PLineMachineStructureImportEntity>(PLineMachineStructureImportEntity.class);
        List<PLineMachineStructureImportEntity> planList = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = pLineMachineStructureService.importPlan(planList, operName);
        return AjaxResult.success(message);
    }
}
